
/// THIS FILE GENERATES REGRESSION TABLES USING CHINESE SAMPLE 	
/// THE REGRESSIONS BELOW USED FOUR DIFFERENT REGRESSION DATASETS 
/// PLEASE SEE THE README FILE FOR DETAILS OF THE RELEVANT DATA 
			
clear all
set more off
set matsize 800


********************************
* Summary Stats 
*********************************

*Table 2 Panel A
use Regscn_fy_all.dta ,clear
tabstat zm lnoutput lnemp tfp_va2_lp lnvapw, by(exporter)
* Table Panel B
use Regscn_fy_expimp.dta, clear
sum zm 
sum lntotexp nhs8_exp nctry_exp 
sum lntotimp nhs8_imp nctry_imp 


***************************************
* Regs on Data 1:  Firm-Year, All Firms 
*****************************************
use Regscn_fy_all.dta ,clear
*Creating Macro 
global noise "aa* reliability reliability_miss i_comptenure i_comptenure_miss dd* i_seniority i_seniority_miss duration duration_miss hour hour_miss " // create noise control macro
global fcont2 "lnkint lnage skill1 lnw" 
global owntype_asie "forhmt_asie soe_asie"
*T3-Col.1,2
qui : eststo T3_c1: xi : areg exporter zm $owntype_asie 					  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo T3_c2: xi : areg exporter zm $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
*APPT2-Col.1,2,3
qui : eststo APPT2_c1 : xi : areg lnprofit zm $owntype_asie					  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo APPT2_c2 : xi : areg lnprofit zm $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo APPT2_c3 : xi : areg lnprofit zm $owntype_asie $fcont2  lndomoutput $noise i.region i.year , absorb(sic) cluster(firmid)
*APPT4-Col.2
qui : eststo APPT4_c2: xi : areg exporter zm $owntype_asie $fcont2 lndomoutput $noise i.region i.year , absorb(sic) cluster(firmid)
*T8-Col.1,2,4
qui : eststo T8_c1: xi : areg tfp_va2_lp zm $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo T8_c2: xi : areg exporter tfp_va2_lp $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
reg tfp_va2_lp zm
predict untfpr_1, resid
qui : eststo T8_c4: xi : bootstrap , reps(600) cluster(firmid) : areg exporter zm untfpr_1 $owntype_asie $fcont2 $noise i.region i.year if zm!=. &  tfp_va2_lp!=., absorb(sic) 
*T9-Col.1
qui : eststo T9_PA_c1: xi : areg exporter zmonit2 zincent2 $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo T9_PB_c1a: xi : areg exporter zmonit2  $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui : eststo T9_PB_c1b: xi : areg exporter zincent2 $owntype_asie $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)

 
****************************************************
*  Regs on Data 2:  Firm-Year, Exporters/Importers
****************************************************

use Regscn_fy_expimp.dta, clear
/* Global Macro */
global noise " aa* reliability reliability_miss i_comptenure i_comptenure_miss dd* i_seniority i_seniority_miss duration duration_miss hour hour_miss agent " 
global fcont2 "lnkint lnage skill1 lnw" 
global owntype_ccts "for_ccts soe_ccts"
*T3-col.3,4
qui: eststo T3_c3: xi : areg  lntotexp zm $owntype_ccts i.region i.year $noise,   absorb(sic) cluster(firmid)
qui: eststo T3_c4: xi : areg  lntotexp zm $owntype_ccts $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
*T4-col.1-5
qui eststo T4_c1: xi : areg  lnnctry_exp zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T4_c2: xi : areg  lnnhs8_exp  zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T4_c3: xi : areg  lnnch8_exp  zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T4_c4: xi : areg  lnavch8_exp zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T4_c5: xi : areg  lnvaex_topch8 zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
*APPT3-col.1-5
qui eststo APPT3_c1: xi : areg  lnnctry_exp zm $owntype_ccts 	 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo APPT3_c2: xi : areg  lnnhs8_exp  zm $owntype_ccts 	 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo APPT3_c3: xi : areg  lnnch8_exp  zm $owntype_ccts 	 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo APPT3_c4: xi : areg  lnavch8_exp zm $owntype_ccts 	 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo APPT3_c5: xi : areg  lnvaex_topch8 zm $owntype_ccts 	 i.region i.year $noise , absorb(sic) cluster(firmid)
* APPT4_col.1,3-5
rename lndomoutput lndm
gen lndomoutput=lndm 
replace lndomoutput=-99 if lndomoutput==.
gen misslndomoutput=(lndomoutput==-99)
qui eststo APPT4_c1: xi : areg  lndomoutput  zm  misslndomoutput $owntype_ccts  $fcont2 i.region i.year $noise if totexp>0 , absorb(sic) cluster(firmid)
qui eststo APPT4_c3: xi : areg  lntotexp    zm $owntype_ccts lndomoutput misslndomoutput	 $fcont2 i.region i.year $noise,  absorb(sic) cluster(firmid)
qui eststo APPT4_c4: xi : areg  lnnch8_exp  zm $owntype_ccts lndomoutput misslndomoutput    $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo APPT4_c5: xi : areg  lnavch8_exp zm $owntype_ccts lndomoutput misslndomoutput    $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
* T6_col.1,2,3
qui eststo T6_c1: xi :  areg  lntotimp	    zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T6_c2: xi :  areg  lnimp_intm1   zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T6_c3: xi :  areg  lnincompcwim  zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
*T7_col_1,2,3
qui eststo T7_c1: xi :  areg  lnnctry_imp lnnhs8_exp zm $owntype_ccts   $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T7_c2: xi :  areg  lnnhs8_imp  lnnhs8_exp  zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T7_c3: xi :  areg  lnnch8_imp  lnnhs8_exp  zm $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
*T8_col_3,5,6,10,12
reg tfp_va2_lp zm
predict untfpr_ccts1, resid
qui eststo T8_c3: xi: areg lntotexp tfp_va2_lp $owntype_ccts $fcont2 $noise i.region i.year , absorb(sic) cluster(firmid)
qui eststo T8_c5: xi: bootstrap , reps(600) cluster(firmid) : areg lntotexp zm untfpr_ccts1 $owntype_ccts $fcont2 $noise i.region i.year , absorb(sic) 
qui eststo T8_c6: xi: bootstrap , reps(600) cluster(firmid) : areg lnnch8_exp zm untfpr_ccts1 $owntype_ccts $fcont2 $noise i.region i.year , absorb(sic) 
qui eststo T8_c10: xi: bootstrap , reps(600) cluster(firmid) :  areg  lnincompcwim  zm untfpr_ccts1 $owntype_ccts $fcont2 $noise i.region i.year  , absorb(sic) 
qui eststo T8_c12: xi: bootstrap , reps(600) cluster(firmid) :  areg  lnnch8_imp    zm untfpr_ccts1 $owntype_ccts $fcont2 $noise i.region i.year  , absorb(sic) 
*T9 Col 2,3,7,9
qui eststo T9_PA_c2:  xi :  areg lntotexp zmonit2 zincent2 $owntype_ccts $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui eststo T9_PB_c2a: xi : areg lntotexp zmonit2  $owntype_ccts $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui eststo T9_PB_c2b: xi : areg lntotexp zincent2 $owntype_ccts $fcont2  $noise i.region i.year , absorb(sic) cluster(firmid)
qui eststo T9_PA_c3:  xi :  areg lnnch8_exp zmonit2 zincent2  $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c3a: xi : areg lnnch8_exp zmonit2 $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c3b: xi : areg lnnch8_exp zincent2  $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PA_c7:  xi :  areg lnincompcwim zmonit2 zincent2 $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c7a: xi : areg lnincompcwim zmonit2 $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c7b: xi : areg lnincompcwim zincent2 $owntype_ccts $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PA_c9:  xi :  areg lnnch8_imp	 zmonit2 zincent2 $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c9a: xi : areg lnnch8_imp	 zmonit2 $owntype_ccts 	$fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)
qui eststo T9_PB_c9b: xi : areg lnnch8_imp	 zincent2 $owntype_ccts $fcont2 i.region i.year $noise , absorb(sic) cluster(firmid)

************************************************
* Regs on Data 3:  Firm-Product-Country-Year
*           Exports
*************************************************
use Regscn_fpc_exp.dta, clear
/* Global Macro */
global owntype_ccts "for_ccts soe_ccts"
global noise "aa* reliability reliability_miss i_comptenure i_comptenure_miss dd* i_seniority i_seniority_miss duration duration_miss hour hour_miss agent i.matchm " 
global fcont5a "lnkint lnage skill1 lnw "
*T5_c1-4
qui eststo T5_c1: xi  : areg  quality5 zm $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T5_c2: xi  : areg  lnqap5   zm $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T5_c3: xi  : areg  lnunitv  zm $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T5_c4: xi  : areg  lnq      zm $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
* APPT5_PanA_c1,2 (NB: c3 and c4 are identical to T5 col. 3,4) 
qui eststo APPT5_PAc1: xi  : areg  quality_bw zm $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo APPT5_PAc2: xi  : areg  lnqap_bw zm $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
* APPT5_PanB_c1,2,3,4
replace fmktp_h8cy=-999 if fmktp_h8cy==.
gen dm_fmktp_h8cy=(fmktp_h8cy==.)
qui eststo APPT5_PBc1: xi  : areg  quality5 zm fmktp_h8cy dm_fmktp_h8cy $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo APPT5_PBc2: xi  : areg  lnqap5   zm fmktp_h8cy dm_fmktp_h8cy $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo APPT5_PBc3: xi  : areg  lnunitv  zm fmktp_h8cy dm_fmktp_h8cy $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo APPT5_PBc4: xi  : areg  lnq      zm fmktp_h8cy dm_fmktp_h8cy $fcont5a  $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
*T8_c7-9
qui eststo T8_c7: xi: bootstrap , reps(600) cluster(firmid) : areg  quality5 zm untfpr_ccts1 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1, absorb(g_ctryhs8) 
qui eststo T8_c8: xi: bootstrap , reps(600) cluster(firmid) : areg  lnqap5   zm untfpr_ccts1 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1, absorb(g_ctryhs8) 
qui eststo T8_c9: xi: bootstrap , reps(600) cluster(firmid) : areg  lnunitv  zm untfpr_ccts1 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1, absorb(g_ctryhs8) 
*T9_c4-6
qui eststo T9_PA_c4:  xi  : areg  quality5 zmonit2 zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c4a: xi  : areg  quality5 zmonit2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c4b: xi  : areg  quality5 zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PA_c5:  xi  : areg  lnqap5 zmonit2 zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c5a: xi  : areg  lnqap5 zmonit2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c5b: xi  : areg  lnqap5 zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PA_c6:  xi  : areg  lnunitv zmonit2 zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c6a: xi  : areg  lnunitv zmonit2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c6b: xi  : areg  lnunitv zincent2 $fcont5a $noise $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)


************************************************
*  Regs on Data 4:  Firm-Product-Country-Year
*           Imports
*************************************************
use Regscn_fpc_imp.dta, clear
/* Global Macro */
global owntype_ccts "for_ccts soe_ccts"
global noise "aa* reliability reliability_miss i_comptenure i_comptenure_miss dd* i_seniority i_seniority_miss duration duration_miss hour hour_miss agent i.matchm " 
global fcont5a "lnkint lnage skill1 lnw "
* T6_c4-5
qui eststo T6_c4: xi  : areg  lnunitv  zm $noise  $fcont5a i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T6_c5: xi  : areg  quality5 zm $noise  $fcont5a i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
*T8 c11
qui eststo T8_c11: xi: bootstrap , reps(600) cluster(firmid) : areg  quality5  zm untfpr_ccts1 $noise  $fcont5a $owntype_ccts i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) 
*T9 c8
qui eststo T9_PA_c8: xi  :  areg  quality5 zmonit2 zincent2 $noise  $fcont5a i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c8a: xi  : areg  quality5 zmonit2 $noise  $fcont5a i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)
qui eststo T9_PB_c8b: xi  : areg  quality5 zincent2 $noise  $fcont5a i.region i.year  if no_out_lnunit==1 & quantity>1,   absorb(g_ctryhs8) cluster(firmid)


************************************************
**      Display All Regression Tables 
************************************************
* Main Tables
esttab T3_c* using Table3_c1-4.csv , drop(_I* aa* dd* rel* i_* dur* hour* agent* skill* for* soe*)  t r2  title( T3,col.1-4, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T4_c* using Table4_c1-5.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont2  for* soe*)  t r2  title( T4,col.1-5, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T5_c* using Table5_c1-4.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent*  $fcont2  for* soe*) t r2  title( T5,col.1-4, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T6_c* using Table6_c1-5.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent*  $fcont2  for* soe*) t r2  title( T6,col.1-5, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T7_c* using Table7_c1-3.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent*  $fcont2 for* soe*)  t r2  title( T7,col.1-3, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T8_c1 T8_c2 T8_c3 T8_c4 T8_c5 T8_c6 T8_c7 T8_c8 T8_c9 T8_c10 T8_c11 T8_c12 using Table8_c1-12.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont2 for* soe*)  t r2  title( T8,Panel A,col.1-12, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T9_PA_c1 T9_PA_c2 T9_PA_c3 T9_PA_c4 T9_PA_c5 T9_PA_c6 T9_PA_c7 T9_PA_c8 T9_PA_c9 using Table9PA_c1-9.csv, drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont2  for* soe*)  t r2  title( T9,Panel A , S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T9_PB_c1a T9_PB_c2a T9_PB_c3a T9_PB_c4a T9_PB_c5a T9_PB_c6a T9_PB_c7a T9_PB_c8a T9_PB_c9a using Table9PB_c1-9r1.csv, drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont2  for* soe*)  t r2  title( T9,Panel B Monitor, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 
esttab T9_PB_c1b T9_PB_c2b T9_PB_c3b T9_PB_c4b T9_PB_c5b T9_PB_c6b T9_PB_c7b T9_PB_c8b T9_PB_c9b using Table9PB_c1-9r2.csv, drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont2  for* soe*)  t r2  title( T9,Panel B Incentives, S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4) 

* Appendix Tables 
esttab APPT2_c* using APPTable2_c1-3.csv,  drop(_I* aa* dd* rel* i_* dur* hour* skill*   for* soe*)  t r2  title( APPT2,col.1-3 ; S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4)  
esttab APPT3_c* using APPTable3_c1-5.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent*   for* soe*)  t r2  title( APPT3,col.1-5 ; S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4)  
esttab APPT4_c* using APPTable4_c1-5.csv,  drop(_I* aa* dd* rel* i_* dur* hour* agent* miss*  $fcont5a  for* soe*)  t r2  title( APPT4,col.1-5;  S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4)  
esttab APPT5_PA* using APPTable5PA_c1-4.csv, drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont5a  for* soe* )  t r2  title(APPT5, Panel A ,col.1-4; S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4)  
esttab APPT5_PB* using APPTable5PB_c1-4.csv, drop(_I* aa* dd* rel* i_* dur* hour* agent* $fcont5a  for* soe* dm*)  t r2  title(APPT5, Panel B, col.1-4 ; S.E.Cluster Firm) star(* 0.10 ** 0.05 *** 0.01) b(a4)  


